// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
//------------ 以下为新增内容-------
//引入ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from "axios";
//配置使用ElementUI
Vue.use(ElementUI)
//---------------------------------
Vue.config.productionTip = false
//在Vue中配置axios，在所有的Vue组件中就可以通过this.axios使用axios库
/*
     axios拦截器
   */
axios.interceptors.request.use(function(config) {
  if(localStorage.getItem("token")){
    config.headers.token = localStorage.getItem("token");
  }
  return config;
})
axios.interceptors.response.use(function(res) {
  if(res.data.state==401){
    localStorage.removeItem("token");
    router.replace({path: "/"});
  }
  return res;
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
